package com.twu.biblioteca;

/**
 * Created by sravanns on 19/06/14.
 */
public class CheckOutMovie implements MenuAction {
    private Library library;
    private UserInterface UIApplication;

    public CheckOutMovie(Library obj, UserInterface ui) {
        library = obj;
        UIApplication =ui;
    }
    @Override
    public String toString() {
        return "Check Out Movie";
    }

    @Override

    public Result performAction(String user) throws InterruptedException {
        UIApplication.display("Enter Movie Name");
        String input = UIApplication.acceptTitle();
        Result result=new Result();

        Movie movie = library.getMovieFromList(input);
        if (movie != null) {
            if (library.checkOutMovie(movie,user)) {

                result.setResult("Thank you! Enjoy the movie",true);

            } else
                result.setResult("That movie is not available. might be checked out already",false);

        }
        else
            result.setResult("That movie is not available in Library. please consider checking the spelling",false);
        return result;
    }

}
